//
//  AppInfo.m
//  AppManager
//
//  Created by allen on 16/3/29.
//  Copyright © 2016年 allen. All rights reserved.
//

#import "AppInfoModel.h"

@interface AppInfoModel()
{
    UIImage *_imageABC;
}
@end

@implementation AppInfoModel

- (instancetype)initWithDict:(NSDictionary *)dict{
    self = [super init];
    if(self){
        self.name = dict[@"name"];
        self.icon = dict[@"icon"];
    }
    return self;
}

+ (instancetype)appInfoWithDict:(NSDictionary *)dict{
    return [[self alloc] initWithDict:dict];
}

- (UIImage *)image{
    if(!_imageABC){
        _imageABC = [UIImage imageNamed:self.icon];
    } 
    return _imageABC;
}

+ (NSArray *)appInfoList{
    // 获取对应资源的路径path
    NSString * path = [[NSBundle mainBundle]pathForResource:@"app" ofType:@"plist"];
    // 根据资源路径获取数组
    NSArray * array = [NSArray arrayWithContentsOfFile:path];
    // 创建一个可变数组来存储对象
    NSMutableArray * arrayM = [NSMutableArray array];
    for(NSDictionary * dict in array){
        [arrayM addObject:[AppInfoModel appInfoWithDict:dict]];
    }
    return arrayM;
}

@end

